package com.ymh.spring.springmvc.config;

import javax.servlet.Filter;
import javax.servlet.Registration.Dynamic;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import org.springframework.web.WebApplicationInitializer;

public class MyServletInitializer implements WebApplicationInitializer {

	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {
		
		//注册Servlet
		Dynamic myservlet = servletContext.addServlet("myServlet", (Class<? extends Servlet>) MyServlet.class);
		//映射Servlet
		((ServletRegistration) myservlet).addMapping("/custom/**");
		
		//注册过滤器Filter
		javax.servlet.FilterRegistration.Dynamic  myFilter = servletContext.addFilter("myFilter", (Class<? extends Filter>) MyFilter.class);
		//添加Filter的映射路径
		myFilter.addMappingForUrlPatterns(null, false, "/custom/**");
	}

}
